package cn.edu.gzist.rabbit.service;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

@Service
public class TopicReceiver {
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue("xiaomi"),
                    exchange = @Exchange(
                            value = "topic.exchange",type = ExchangeTypes.TOPIC
                    ),
                    key = "xiaomi.#"))
    public void handler1(String msg) {
        System.out.println("TopicReceiver:handler1 xiaomi.#:" + msg);
    }

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue("huawei"),
                    exchange = @Exchange(
                            value = "topic.exchange",type = ExchangeTypes.TOPIC
                    ),
                    key = "huawei.#"))
    public void handler2(String msg) {
        System.out.println("TopicReceiver:handler2 huawei.#:" + msg);
    }
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue("phone"),
                    exchange = @Exchange(
                            value = "topic.exchange",type = ExchangeTypes.TOPIC
                    ),
                    key = "phone.#"))
    public void handler3(String msg) {
        System.out.println("TopicReceiver:handler3 phone.#:" + msg);
    }
}
